#pragma once

class runtimeException{
public:
	enum fbErrorCode
	{
		fbNoError,
		fbArithmeticOverflow,
		fbDivideByZero,
		fbTypeMismatch,
		fbResumeWithoutError,
		fbSubscriptOutOfRange
	};
	runtimeException() { errno = fbNoError; }
	runtimeException(fbErrorCode e){errno=e;}
private:
	fbErrorCode errno;
};

#define ON_ERROR_RESUME_NEXT ;
#define ON_ERROR_GOTO(jumplabel) ;
#define ERROR_HEADER int _except_jumpid=0;bool _except_resume_next=false;
#define DEF_LABEL(x) x: ;
#define ERROR_SAFE_SKIP_START try{
#define ERROR_SAFE_SKIP_END }catch(runtimeException){}
#define ERROR_SAFE_START(jumpid) except_resume##jumpid: try{
#define ERROR_SAFE_END(jumplabel,jumpid) }catch(runtimeException){_except_jumpid=jumpid;goto l##jumplabel;}DEF_LABEL(except_next##jumpid)


#define EXCEPTION_JUMP_TABLE_START					goto _skip_jump_table;			\
													_jump_table_start:	\
													switch (_except_jumpid){
														
#define EXCEPTION_ENTRY(jumpid)						case jumpid :					\
													_except_jumpid=0;				\
													if (_except_resume_next)		\
														goto except_next##jumpid;	\
													else							\
														goto except_resume##jumpid;	
													
#define EXCEPTION_RESUME							if (_except_jumpid==0) throw runtimeException(runtimeException::fbResumeWithoutError);_except_resume_next=false;goto _jump_table_start;
#define EXCEPTION_RESUME_NEXT						if (_except_jumpid==0) throw runtimeException(runtimeException::fbResumeWithoutError);_except_resume_next=true;goto _jump_table_start;


#define EXCEPTION_JUMP_TABLE_END					}_skip_jump_table:;


